package com.abyss.source;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 从socket server中获取网络套接字数据(字符数据)
 * 在Linux中，使用nc -lk 端口号监听端口，并发送单词
 */
public class SocketSourceDemo {
    public static void main(String[] args) throws Exception {
        // 1. Env
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        // 2. source
        // 意思是连接node1机器的9999端口的socket server，获取server提供的数据
        DataStreamSource<String> socketTextStream = env.socketTextStream("node1", 9999);

        socketTextStream.print();
        env.execute();
    }
}